package de.hauck.rtmidlet.views;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import de.hauck.rtmidlet.RTMidlet;
import de.hauck.rtmidlet.utils.Utils;

public class CanvasSuper extends Canvas implements CommandListener, iCanvas {
	private Font f_small, f_med;
	private Image _image;
	private Displayable _dble;
	private Image conn_red, conn_yellow, conn_green, conn_status;
	private String _name = "";
	private Calendar cal;

	public CanvasSuper() {
		//_dble = dble;
		cal = Calendar.getInstance();
		// cal.setTime(new Date(System.currentTimeMillis()));
		setFullScreenMode(true);
		setCommandListener(this);
		try {
			conn_red = Image.createImage("/conn_red.png");
			conn_yellow = Image.createImage("/conn_yellow.png");
			conn_green = Image.createImage("/conn_green.png");
			conn_status = conn_red;
		} catch (IOException e) {
			e.printStackTrace();
		}

		f_small = Font.getFont(Font.FONT_STATIC_TEXT, Font.STYLE_PLAIN,
				Font.SIZE_SMALL);
//		f_med = Font.getFont(Font.FONT_STATIC_TEXT, Font.STYLE_PLAIN,
//				Font.SIZE_MEDIUM);
	}

	protected void paint(Graphics g) {
		g.setColor(0);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setColor(255, 255, 255);
		g.setFont(f_small);
		g.drawString(Utils.convertCal2DateTimeStamp(cal), getWidth() - 10, 1,
				Graphics.TOP | Graphics.RIGHT);
		g.drawImage(conn_status, getWidth(), 1, Graphics.TOP | Graphics.RIGHT);

	}

	public void commandAction(Command arg0, Displayable arg1) {

	}

	protected void keyPressed(int keyCode) {
//		if (keyCode == -6 || keyCode == -7) {
//			System.out.println("super back");
//			RTMidlet.getInstance().show(_dble);
//		}
	}

	public void downloadPic(String name, String url) {
		// TODO Auto-generated method stub

	}

	public void showPic(Image image) {
		// TODO Auto-generated method stub

	}

	public void updateStatus(int i) {
		switch (i) {
		case 0: {
			conn_status = conn_red;
			repaint();
			break;
		}
		case 1: {
			conn_status = conn_yellow;
			repaint();
			break;
		}
		case 2: {
			conn_status = conn_green;
			repaint();
			break;
		}
		}
		cal.setTime(new Date(System.currentTimeMillis()));
	}

}
